<?php
/**
 * Pipahr
 *
 * @author Chin Win
 * @copyright 2013 pipahr.com
 */
require_once(OC_App::getAppPath('calendar') . "/lib/helper.php");
JLoader::register("PCalendarModellistview", OC_App::getAppPath('calendar') . "/lib/listview.php");

OCP\JSON::callCheck();
if(!OC_User::isLoggedIn()) {
   echo '您需要先登录';
   exit;
}

$jobseekid = JRequest::getInt('jobseekid', 0);
$jobid = JRequest::getInt('jobid',0);
$user = PFactory::getUser();

$model = new PCalendarModellistview();

$interviewfeedbacklists = $model->getInterviewFeedbackList($jobseekid);

$interviewfeedbackpage = OC_Helper::linkToRoute("calendar_interviewfeedback", array('jobseekerid'=>$jobseekid));

if(empty($interviewfeedbacklists)) {
   echo '<div class="modal changeinterview_dialog feedback_dialog nodatafeedback_dialog">
            <div class="topsj"></div>
            <div class="modal-header clearfix">
               <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
               <a href="'.$interviewfeedbackpage.'" class="btn btn_feedback" target="_blank">预览反馈表</a>
               <h3 class="songti nodatafeedback">尚无反馈</h3>
            </div>
         </div>';
   exit();
}else{
   echo '<div class="modal changeinterview_dialog feedback_dialog">
            <div class="topsj"></div>
            <div class="modal-header clearfix">
               <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
               <h3 class="songti">面试反馈</h3>
            </div>
         <div class="modal-body medium">
         <div class="feedback_dialogtable">
            <table width="100%" border="0" cellpadding="0" cellspacing="0">
               <tr>
                  <th width="140" align="left">姓名</th>
                  <th width="140">时间</th>
                  <th width="100" align="left">反馈结果</th>
                  <th align="left">面试阶段</th>
               </tr> ';
   $ismanager = PCompanyHelper::checkJobManagerPermissions($jobid);
   foreach ($interviewfeedbacklists as $key=>$feedbacklists){
      $fb_time = empty($feedbacklists['fb_time'])?'--':JHtml::_('date',$feedbacklists['fb_time']);
      if($ismanager){
         $suggestion = empty($feedbacklists['suggestion'])?false:$feedbacklists['suggestion'];
      }else{
         $suggestion = empty($feedbacklists['suggestion'])?'--':$feedbacklists['suggestion'];
      }

      $link  = $feedbacklists['suggestion_id'] === null ?'"javascript:;"':'"'.OC_Helper::linkToRoute("calendar_interviewfeedback", array('id'=>$feedbacklists['objectid'])).'"';
      $id    = $feedbacklists['suggestion_id'] === null ?'id="remind"':'';
      $blink = $feedbacklists['suggestion_id'] === null ?'':'target="_blank"';
      $style = $feedbacklists['suggestion_id'] === null ?'style="color:#d2871d"':'';
      
      $suggestion = $feedbacklists['suggestion_id'] === null ? "提醒反馈" : ($feedbacklists['suggestion_id'] === '0' ? '应聘者缺席' : $suggestion);

      if (empty($feedbacklists['suggestion']) && ($feedbacklists['user_email'] == $user->username || $feedbacklists['user_email'] == $user->email)) {
         $suggestion = "写反馈";
         $link = PCalendarHelper::getPublicShareLink('event',$feedbacklists['token'],$feedbacklists['user_email']).'&feedback=1';
      }

      echo '<tr>
            <td style="word-break:break-all;">'.strmaxtextlen($feedbacklists['interviewers'],9).'</td>
            <td align="center">'.$fb_time.'</td>';
      if($suggestion == '--'){
         echo '<td style="color:#1696bd;">'.$suggestion.'</td>';
      }else{
         if ($feedbacklists["suggestion_id"] === '0' || $feedbacklists['suggestion_id'] == 6) {
            echo '<td>' . $suggestion . '</td>';
         } else {
            echo '<td><a data="{objectid:'.$feedbacklists['objectid'].',jobid:'.$feedbacklists['jobid'].'}" href='.$link.' '.$blink.' '.$id.' '.$style.'>'.$suggestion.'</a></td>';
         }
      }
      echo '<td>';
      if($feedbacklists["absent_flag"] == 1) {
         echo "缺席";
      } else {
         if($feedbacklists['round'] ==1 ){
            echo'初试';
         }else{
            echo'第'.($feedbacklists['round']).'轮面试';
         }
      }
      echo '</td>
            </tr>';
   }
   echo'</table>
        </div>
        </div>
   	    </div>';
   exit();
}
